package com.atguigu.study.bootredis.zookeeper.controller;

import com.atguigu.study.bootredis.zookeeper.lock.ZkLock;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jiangta
 * @version 1.0
 * @date 2021/1/7 4:31 下午
 */
@RestController
@Slf4j
public class ZookeeperController {

    @RequestMapping("zkLock")
    public void zookeeperLock() {
        log.info("我进入了方法");
        try(ZkLock zkLock = new ZkLock()) {
            if(zkLock.getLock("order")) {
                log.info("我获得了锁");
                Thread.sleep(1000);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("我离开了方法");
    }
}
